﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Web.Security;
using project.WebServices;

/*
 * ==================================================================================
 * Author: Sneha Nagendra / Anusha K U
 * Created On: 08-03-2011 03:00 pm IST
 * This page confirms a successful logout and provides a link to the home page.
 * ==================================================================================
 */


namespace project.GUI
{
    public partial class Logout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
                Response.Expires = -1500;
                Response.CacheControl = "no-cache";
                SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
                SqlCommand command = new SqlCommand("sp_UserLogout", connect);
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@par_userid", System.Data.SqlDbType.Int)).Value = (int)Session["userid"];
                connect.Open();
                command.ExecuteNonQuery();
                connect.Close();
                connect.Dispose();
                LogService logService = new LogService();
                logService.LogAction("User " + (string)Session["username"] + " has logged out.");
                FormsAuthentication.SignOut();
                Roles.DeleteCookie();
                Session.Clear();
                Server.Transfer("~/GUI/Login.aspx");
            }
            catch (Exception ex)
            {
                Server.Transfer("~/GUI/Error.aspx");
            }
            Server.Transfer("~/GUI/Login.aspx");

        }
    }
}
